Application Class

Includes properties, methods, and events for managing the application as a whole.

Events

Activate

HandleAppleEvent

CancelClose

NewDocument

Close

Open

Deactivate

OpenDocument

EnableMenuItems

UnhandledException


Properties

AcceptFileTypes

ExecutableFile

NonReleaseVersion

AutoQuit

LongVersion

PackageInfo

BalloonHelpVisible

MajorVersion

RegionCode

BugVersion

MDIWindow

ResourceFork

BuildDate

MenuBar

ShortVersion

CurrentThread

MinorVersion

StageCode

DockItem

MouseCursor

 

Methods

AddTrayItem

DoEvents

NewDocument

OpenDocument

RemoveTrayItem

SleepCurrentThread

YieldToNextThread


More information available in parent classes: Object


Notes

REALbasic adds a class based on the Application class to the Project Editor when you create a new Desktop Application project. This new subclass will give you access to the Application object's methods and events. If you created a Console Application, the App class's Super class is ConsoleApplication, not Application.

If you wish, you can add additional subclasses based on the Application class to the project, but it is not necessary. If you do so, the one that is added to the project automatically is the one referred to by the App function and it is the one that will show the project's build settings.

The new subclass has its own menu handlers which can be used to handle menus items when no windows are open or for menu items that should call the same menu handler regardless of which window is frontmost. You can change the global menubar by assigning a different menubar to its MenuBar property.

See the Control class for information on changing the cursor and adding cursors to your project.

The App function returns a reference to the Application object. See the App function for more information.

Resource files (files of type "rsrc") created with a resource editor can be added to your project adding each resource file to the Project. These resources are then accessible through the Application object's ResourceFork property. The resources from all your resource files will be copied into the built Macintosh application. In the case of a conflict, later resource files overwrite earlier ones, where the files are written in the order in which they appear in the Project Editor.

The application resources are read-only. If you need to write to resources you will need to use an external resource file. See the ResourceFork class for more information.

Note: Access to the resourcefork is supported only on Macintosh. Check the value of the TargetMacOS constant before attempting to access the application's resourcefork.

Version Information

The compiler autoincrements version information for a project on each compile.This includes test compiles within the debugger as well as standalone builds.

The compiler truncates version information when building Windows applications when the version information is too long to store into the executable file. The current byte limitations for these fields are as follows:

FieldMaximum length (bytes)
Long Version 79
Short Version 39
Package Info 253
Region 21
Release 11


Examples

The following code in the Action event of a PushButton causes an OutOfBoundsException runtime error when the counter, i, reaches the value of FontCount.

Dim i as Integer
For i=1 to FontCount
 ListBox1.Addrow Font(i)
Next

Since there is no exception handler within the method, the runtime exception is passed up to the Application class, triggering the UnhandledException event.

This code in the UnhandledException event of the App class "catches" the unhandled OutOfBoundsException. Of course, it catches all unhandled OutOfBoundsExceptions throughout the application, so it doesn't know where the error occurred. You could instead place an Exception Block within the PushButton's Action event so that you can provide more specific diagnostics.

Function UnhandledException(error as RuntimeException) as Boolean
 If error IsA OutOfBoundsException then
   MsgBox "An OutOfBounds Exception error has occurred!"
 End if
 Return True

See Also

App, ResourceFork, System, objects; AppleEvent, ConsoleApplication, MDIWindow, ServiceApplication classes.